<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ViewRequest</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
    <button @click="moveNode">moveNode</button>
    <button @click="addNode">addNode</button>
    <button @click="getStructureOfChildTree">getStructureOfChildTree</button>
    <button @click="addTagToNode">addTagToNode</button>
    <button @click="deleteTagFromNode">deleteTagFromNode</button>
    <button @click="addInfo">addInfo</button>
    <button @click="deleteInfo">deleteInfo</button>
    <button @click="getInfosByTagUnion">getInfosByTagUnion</button>
</div>
<script>
    const send = (req) => {
        axios({
            method: "post",
            url: "http://localhost:80/view",
            data: req
        }).then(function (resp) {
            console.log(resp.data)
        })
    }
    var vm = new Vue({
        el: '#app',
        methods: {
            moveNode() {
                let req = {
                    type: "req_moveNode",
                    value: {
                        from: "",
                        to: ""
                    }
                }
                send(req);
                let resp = {
                    type: "req_moveNode",
                    isSuccess: true,
                    err: "",//可选
                    code: ""//可选
                }
            },
            addNode() {
                let node = {
                    type: "",
                    name: "",
                }
                let req = {
                    type: "req_addNode",
                    value: {
                        path: "",
                        node: node
                    }
                }
                send(req);
                //返回的时候应该不需要node的ID，因为是靠getStructureOfTree()全部刷新的
                let resp = {
                    type: "req_addNode",
                    isSuccess: true
                }
            },
            deleteNode(){
                let req = {
                    type: "req_deleteNode",
                    value: "path"
                }
                send(req);
            },
            updateNode(){
                let req = {
                    type: "req_updateNode",
                    value: {...}
                }
                send(req);
            },
            getStructureOfChildTree() {
                let req = {
                    type: "req_getStructureOfChildTree",
                    value: {
                        path: ""
                    }
                };
                send(req);
                //node树的深度只需要到“文章”这个类型即可，文章内部不需要
                let node = {
                    type: "",
                    path: "",
                    name: "",
                    tags: ["tagid","tagid"],
                    // node[]
                    children: {}
                };
                let resp = {
                    type: "req_getStructureOfChildTree",
                    isSuccess: true,
                    value: node
                }
            },
            addTagToNode() {
                let req = {
                    type: "req_addTagToNode",
                    value: {
                        path: "",
                        tagId: ""
                    }
                };
                send(req);
            },
            deleteTagFromNode() {
                let req = {
                    type: "req_deleteTagFromNode",
                    value: {
                        path: "",
                        tagId: ""
                    }
                };
                send(req);
            },
            addInfo() {//可以废弃，被updateNode取代
                let req = {
                    type: "req_addInfo",
                    value: {
                        path: "",
                        infoId: ""
                    }
                };
                send(req);
            },
            deleteInfo() {//可以废弃，被updateNode取代
                let req = {
                    type: "req_deleteInfo",
                    value: {
                        path: "",
                        infoId: ""
                    }
                };
                send(req);
            },
            //当务之急
            getInfosByTagUnion(){
                let req={
                    type:"req_getInfosByTagUnion",
                    value:{
                        normal:['tagid','tagid'],
                        special:[{
                            id:"",//特殊标签有不变且唯一的id，最好有什么办法能迅速判断是否是特殊标签，id<多少，或者弄个方法去查，或者前端做个hash
                            //name:"others",
                            value:['tagid','tagid']
                        }]
                    }
                }
                send(req);
                let resp={
                    type:"resp_getInfosByTagUnion",
                    isSuccess:true,
                    value:[{},{},{}]
                }
            },
        }
    })
</script>
</body>
</html>